<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: shopping_cart.php 140 2013-09-22 07:44:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 140 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:44:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if ($_SESSION['customers_status']['customers_status_show_price'] == 1) {
	$box_smarty = new Smarty();
	$box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	$box_smarty->assign('ajax', (isset($ajax_status) ? $ajax_status : false));
	$box_smarty->assign('cart_in_col', ($get_box->fields['position'] == 'left' || $get_box->fields['position'] == 'right' ? 'true' : 'false'));
	
	$box_price_string = '';
	require_once (DIR_FS_INC.'inc.recalculate_price.php');

	if(strstr($PHP_SELF, FILENAME_CHECKOUT_PAYMENT) || strstr($PHP_SELF, FILENAME_CHECKOUT_CONFIRMATION) || strstr($PHP_SELF, FILENAME_SHOPPING_CART) || strstr($PHP_SELF, FILENAME_CHECKOUT_SHIPPING))
		$box_smarty->assign('deny_cart', 'true');

	if($_SESSION['cart']->count_contents() > 0) {
		$products = $_SESSION['cart']->get_products();
		$products_in_cart = array ();
		$qty = 0;
		for ($i = 0, $n = sizeof($products); $i < $n; $i ++) {
			$qty += $products[$i]['quantity'];

			$img = (!empty($products[$i]['image']) ? '<img '.get_img_size($products[$i]['image']).' src="'.$products[$i]['image'].'" class="box_cart_img" alt="'.$products[$i]['name'].'" />' : '&nbsp;');

			$products_in_cart[] = array('QTY' => $products[$i]['quantity'],
										'ID' => $products[$i]['id'],
									 	'LINK' => href_link(FILENAME_PRODUCT_INFO, product_link($products[$i]['id'], $products[$i]['name'])),
									 	'PRICE' => $price->format($products[$i]['price'], true),
									 	'IMAGE' => $img,
									 	'NAME' => $products[$i]['name']);
		}
		$box_smarty->assign('PRODUCTS', $qty);
		$box_smarty->assign('LAST', LAST_ADDED);
		$box_smarty->assign('TOTAL_PRODUCTS', $_SESSION['cart']->count_contents());
		$box_smarty->assign('empty', 'false');

	} else {
		$box_smarty->assign('empty', 'true');
		$box_smarty->assign('CUR', $_SESSION['currency']);
	}

	if ($_SESSION['cart']->count_contents() > 0) {
		$total = $_SESSION['cart']->show_total();
		if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1' && $_SESSION['customers_status']['customers_status_ot_discount'] != '0.00') {
			if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1)
				$Dprice = $total-$_SESSION['cart']->show_tax(false);
			else
				$Dprice = $total;

			$discount = $price->GetDiscount($Dprice, $_SESSION['customers_status']['customers_status_ot_discount']);
			$box_smarty->assign('DISCOUNT', $price->format(($discount * (-1)), 1, false));
			$box_smarty->assign('DISCOUNT_AMOUNT', $_SESSION['customers_status']['customers_status_ot_discount'].'% ');
		}

		if ($_SESSION['customers_status']['customers_status_show_price'] == '1') {
			if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) $total-=$discount;
			if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) $total-=$discount;
			if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) $total-=$discount;
			$box_smarty->assign('TOTAL', $price->format($total, true).'*');
		}

		$box_smarty->assign('UST', $_SESSION['cart']->show_tax());

		if(SHOW_SHIPPING == 'true')
			$box_smarty->assign('SHIPPING_INFO', $main->getShippingLink());
	}
	if(ACTIVATE_GIFT_SYSTEM == 'true')
		$box_smarty->assign('ACTIVATE_GIFT', 'true');

	if(isset($_SESSION['customer_id'])) {
		$gv = $db->db_query("SELECT amount FROM ".TABLE_COUPON_GV_CUSTOMER." WHERE customer_id = '".$_SESSION['customer_id']."'");
		if ($gv->fields['amount'] > 0) {
			$box_smarty->assign('GV_AMOUNT', $price->format($gv->fields['amount'], true, 0, true));
			$box_smarty->assign('GV_SEND_TO_FRIEND_LINK', '<a href="'.href_link(FILENAME_GV_SEND).'">');
		}
	}
	if(isset($_SESSION['gv_id'])) {
		$coupon = $db->db_query("SELECT coupon_amount FROM ".TABLE_COUPONS." WHERE coupon_id = '".$_SESSION['gv_id']."'");
		$box_smarty->assign('COUPON_AMOUNT2', $price->format($coupon->fields['coupon_amount'], true, 0, true));
	}
	if(isset($_SESSION['cc_id']))
		$box_smarty->assign('COUPON_HELP_LINK', '<a href="javascript:popupWindow(\''.href_link(FILENAME_POPUP_COUPON_HELP, 'cID='.$_SESSION['cc_id']).'\')">');

	$box_smarty->assign('SUBTOTAL', SUBTOTAL);
	$box_smarty->assign('ARTICLE', ARTICLE);
	$box_smarty->assign('COUNT', COUNT);
	$box_smarty->assign('TOTAL_PRICE', TOTAL_PRICE);

	$box_smarty->assign('LINK_CART', href_link(FILENAME_SHOPPING_CART, '', 'SSL'));
	$box_smarty->assign('products', $products_in_cart);

	$box_smarty->caching = false;
	$box_smarty->assign('language', $_SESSION['language']);
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_cart.html');
}